/**
 * @param {number[]} big
 * @param {number[]} small
 * @return {number[]}
 */
var shortestSeq = function(big, small) {
    let left = 0, right = 0, minLens = big.length;
    const map = new Map();
    let result = [];
    while (right < big.length) {
        if (small.includes(big[right])) {
            map.set(big[right], (map.get(big[right]) || 0) + 1);
        }
        while (map.size === small.length) {
            let currLen = right - left + 1;
            if (currLen < minLens) {
                minLens = currLen;
                result = [left, right];
            } else if (currLen === minLens) {
                // 如果长度相同，选择 left 较小的结果
                if (left < result[0]) {
                    result = [left, right];
                }
            }
            if (small.includes(big[left])) {
                if (map.get(big[left]) === 1) {
                    map.delete(big[left]);
                } else {
                    map.set(big[left], map.get(big[left]) - 1);
                }
            }
            left++;
        }
        right++;
    }
    return result;
};

let big = [7, 5, 9, 0, 2, 1, 3, 5, 7, 9, 1, 1, 5, 8, 8, 9, 7];
let small = [1, 5, 9];

console.log(shortestSeq(big, small));